﻿

create proc Projects.UpdateProjectValues
@ShortName			nvarchar(50),
@ErloesSuHw			decimal(11,2), 
@ErloesSuPr			decimal(11,2), 
@ErloesSuMo			decimal(11,2),
@ErloesRaPr			decimal(11,2), 
@ErloesRaLe			decimal(11,2), 
@ErloesRaPro		decimal(11,2), 
@ErloesSf			decimal(11,2), 
@ErloesEm			decimal(11,2), 
@ErloesFa			decimal(11,2),
@CostHandelsware	decimal(11,2), 
@CostProduktion		decimal(11,2), 
@CostMontage		decimal(11,2), 
@CostAdministration	decimal(11,2), 
@ExtraCostBIPercent	decimal(11,2), 
@ExtraCostBIFix		decimal(11,2), 
@ExtraCostPrEPercent	decimal(11,2), 
@ExtraCostPrEFix	decimal(11,2), 
@ExtraCostErfGar	decimal(11,2), 
@ExtraCostHaftRuecklage	decimal(11,2), 
@ExtraCostSkonto	decimal(11,2), 
@ExtraCostProvisionDB	decimal(11,2), 
@TimeProduktion		decimal(11,2), 
@TimeMontage		decimal(11,2), 
@TimeAdministration	decimal(11,2),
@TimeProducts		decimal(11,2),
@UserID				int

as
begin
	set nocount on

	declare @rc int,
			@now datetime2(7) = sysdatetime(),
			@logText nvarchar(150)

	if @ShortName is null
	begin
		Select -1 'Return', 'ShortName is null' 'Error' 
		goto WithError
	end

	set xact_abort on

	begin tran

	begin try

		update	pv
			set
				ErloesSuHw				= @ErloesSuHw, 
				ErloesSuPr				= @ErloesSuPr, 
				ErloesSuMo				= @ErloesSuMo, 
				ErloesRaPr				= @ErloesRaPr, 
				ErloesRaLe				= @ErloesRaLe, 
				ErloesRaPro				= @ErloesRaPro, 
				ErloesSf				= @ErloesSf, 
				ErloesEm				= @ErloesEm, 
				ErloesFa				= @ErloesFa,	 
				CostHandelsware			= @CostHandelsware, 
				CostProduktion			= @CostProduktion, 
				CostMontage				= @CostMontage, 
				CostAdministration		= @CostAdministration,
				ExtraCostBIPercent		= @ExtraCostBIPercent, 
				ExtraCostBIFix			= @ExtraCostBIFix, 
				ExtraCostPrEPercent		= @ExtraCostPrEPercent, 
				ExtraCostPrEFix			= @ExtraCostPrEFix, 
				ExtraCostErfGar			= @ExtraCostErfGar, 
				ExtraCostHaftRuecklage	= @ExtraCostHaftRuecklage, 
				ExtraCostSkonto			= @ExtraCostSkonto, 
				ExtraCostProvisionDB	= @ExtraCostProvisionDB, 
				TimeProduktion			= @TimeProduktion, 
				TimeMontage				= @TimeMontage, 
				TimeAdministration		= @TimeAdministration, 
				TimeProducts			= @TimeProducts

		from	Projects.datProjectsValues pv
				inner join Projects.datProjects p on
					p.ProjectID = pv.ProjectID
		where	p.ShortName = @ShortName
	
	end try
	begin catch
		Select -1 'Return', ERROR_MESSAGE() 'Error' 
		goto WithError
	end catch

	commit tran
	
	return 0

WithError:
	if @@TRANCOUNT > 0
	begin
		set @logText = 'Projects.UpdateProjectValues: ' + cast(@ShortName as char(10))
		exec @rc = dbo.SaveLog
			@UserID = @UserID,
			@LogType = 'S',
			@LogArea = 'Pr',
			@LogDetails = @logText,
			@IsError = 1
		rollback tran
	end
	return -1
				
end